<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
		<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
        <title>Google Books - My Library - Scanner Tool</title>
        <script type="text/javascript">
            //<![CDATA[

function init() {
    var BookUPCs;
    var newUPC;

    document.getElementById("lnkScan").href = "http://zxing.appspot.com/scan?ret=" + location.protocol + "//" + location.host + location.pathname + "?upc={CODE}&SCAN_FORMATS=UPC_A&SCAN_FORMATS=EAN_13";

    if (window.localStorage.BookUPCs !== undefined) {
        BookUPCs = JSON.parse(window.localStorage.BookUPCs);
    } else {
        BookUPCs = [];
    }

    if (window.location.search != "") {
        newUPC = window.location.search.substr(5);  //?upc=##########
        BookUPCs.push(newUPC);
    }

    window.localStorage.BookUPCs = JSON.stringify(BookUPCs);
    document.getElementById("panUPCs").textContent = BookUPCs.join(", ");

    simulateScanClick();
}

function reset() {
    window.localStorage.BookUPCs = JSON.stringify([]);
    document.getElementById("panUPCs").textContent = "";
}

/* window.location didn't work.  got this from dev.moz site.  read up to understand */
function simulateScanClick() {
    var evt = document.createEvent("MouseEvents");
    evt.initMouseEvent("click", true, true, window,0, 0, 0, 0, 0, false, false, false, false, 0, null);
    var canceled = !document.getElementById("lnkScan").dispatchEvent(evt);
    if(canceled) {
        // A handler called preventDefault
        //alert("canceled");
    } else {
        // None of the handlers called preventDefault
        //alert("not canceled");
    }
}

//]]>
        </script>
        <style type="text/css">
        html,body{}
        body{margin:0;padding:0;background:#000;}
        #panUPCs,input{background:#333;color:#fff;border:solid 1px #A4C639;padding:3px;margin:2px 2px 10px;font-size:1em;font-family:sans-serif;}
        .hidden{display:none;}
        </style>
    </head>
    <body onload="init();">
        <div class="hidden">
            <a id="lnkScan" href="http://zxing.appspot.com/scan">SCAN</a>
        </div>
        <div id="panUPCs">
        </div>
        <input type="button" value="Reset" onclick="reset();" />
        <input type="button" value="Scan" onclick="simulateScanClick();" />
    </body>
</html>
